#include "OgreConsole.h"

#include "OgreFramework.h"

OgreConsole::OgreConsole(int commandHistory, int textHistory, bool echo,
                         ConsoleFunction defaultFunction, int commandlineIndex)
    :Console(commandHistory, textHistory, echo, defaultFunction, commandlineIndex)
{

}

OgreConsole::~OgreConsole()
{
}


void OgreConsole::initRender()
{

    Ogre::LogManager::getSingleton().getDefaultLog()->addListener(this);



    Ogre::String infoText = "Console";


    for(std::list<std::string>::const_iterator iter = textBuffer.begin(); iter != textBuffer.end(); ++iter)
    {
        infoText.append(*iter);

    }

    m_textBoxToRender = OgreFramework::getSingletonPtr()->m_pTrayMgr->createTextBox(OgreBites::TL_BOTTOM, "InfoPanel", infoText, 800, 220);
}


void OgreConsole::render()
{
    m_textBoxToRender->clearText();

    Ogre::String infoText = "Console\n";


    for(std::list<std::string>::const_iterator iter = textBuffer.begin(); iter != textBuffer.end(); ++iter)
    {
        infoText.append(*iter);
        infoText.append("\n");

    }
    m_textBoxToRender->setText(infoText);

}


void OgreConsole::messageLogged( const string& message, Ogre::LogMessageLevel lml, bool maskDebug, const string &logName )
{

    print(logName+": "+message);


}



template<> OgreConsole* Ogre::Singleton<OgreConsole>::ms_Singleton = 0;

OgreConsole* OgreConsole::getSingletonPtr(void)
{
    return ms_Singleton;
}
OgreConsole& OgreConsole::getSingleton(void)
{
    assert( ms_Singleton );
    return ( *ms_Singleton );
}
